package com.plug.service;


import com.plug.entity.PlugTaskState;
import com.plug.repository.PlugTaskStateMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by admin on 2017/1/16.
 */
@Service("plugTaskStateService")
public class PlugTaskStateServiceImpl implements IPlugTaskStateService {

    @Autowired
    private PlugTaskStateMapper plugTaskStateMapper;

    //添加一条任务状态记录
    @Override
    public int addTaskState(PlugTaskState plugTaskState) {
        return plugTaskStateMapper.insert(plugTaskState);
    }

    //更改一条记录
    @Override
    public int updateTime(PlugTaskState plugTaskState) {
        return plugTaskStateMapper.updateByPrimaryKeySelective(plugTaskState);
    }

    //分页查询记录
    @Override
    public List<Map<String, Object>> findByPage(int page, int size) {
//        如果传入页码为零，则查询第一页
        int offset;
        if(page==0){
            page=1;
        }

        offset= (page-1)*size;

        int limit;
        if(size==0){
            limit=10;
        }
        limit = size;

        return plugTaskStateMapper.findByPage(offset, limit);
    }

    //查询记录总数
    @Override
    public int findTotal() {
        return plugTaskStateMapper.findTotal();
    }

    @Override
    public PlugTaskState selectByName(String taskName) {
        return plugTaskStateMapper.selectByName(taskName);
    }

    @Override
    public int deleteBatch(List<Integer> list) {
        return plugTaskStateMapper.deleteBatch(list);
    }

    /**
     *  根据任务名称查询 id
     * @param taskNames
     * @return
     */
    public  List<Integer> selectIdByname(List<String> taskNames){
        return plugTaskStateMapper.selectIdByname(taskNames);
    }
}
